<?php

namespace App\Console\Commands\Corn;

use App\Models\OwnerItem;
use App\Services\SendService;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Auth;

class SendMessageToAdmin extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'corn:send-message-to-admin';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '发送短信给管理员';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $total_amount = OwnerItem::query()->where('pay_at', '>', Carbon::now()->subDays(30))->sum('total_amount');
        (new SendService())->qcloud(Auth::guard('admin')->user()->mobile, $total_amount, 'admin');
    }
}
